﻿//======================================================================
//
//	Cross-Platform XNA Menu System
//  http://cpxms.codeplex.com/
//
//  All code and content licensed under Microsoft Public License (Ms-PL)	
//
//======================================================================
//
//	File:		Page.cs
//
//	Author:		MJP
//
//	Date:		04/11/09
//
//======================================================================

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using System.Drawing.Design;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace CPXMenu
{
	/// <summary>
	/// Represents a single page in the menu.  Each page is the size of the screen,
	/// and can hanve multiple items as children.  The project can "flip" between
	/// different pages.
	/// </summary>
    [CanHaveChildren(true)]
    [IconKey("Page")]
    [ParentType(typeof(MenuProject))]
    [Description("Represents a single page in the menu. Each page is the size of the screen, "
	+ "and can hanve multiple items as children.  The project can \"flip\" between "
	+ "different pages.")]
    public class Page : MenuItem
    {
        private ImageState backgroundImage = new ImageState();

		public const string DefaultBackgroundImage = "CPXMenu Content\\Textures\\PageBackground";

		/// <summary>
		/// Gets or sets the relative position of the page.  Always (0,0).
		/// </summary>
        [Browsable(false)]
        [XmlIgnore]
        public override Point Position
        {
            get { return new Point(0, 0); }
            set { }
        }

		/// <summary>
		/// Gets or sets the absolute position of the page.  Alwas (0,0)
		/// </summary>
        [Browsable(false)]
        [XmlIgnore]
        public override Point AbsolutePosition
        {
            get { return new Point(0, 0); }
            set { }
        }

		/// <summary>
		/// Gets or sets the dimensions of the page.  Always equal to the project dimensions.
		/// </summary>
        [Browsable(false)]
        public new Point Dimensions
        {
            get { return base.Dimensions; }
            set { base.Dimensions = value; }
        }

		/// <summary>
		/// Gets or sets the ImageState that describes the background image and color of the page
		/// </summary>
        [Browsable(true)]
        [Category("Appearance")]
        [Description("Describes the background color and image of the page")]
        public ImageState BackgroundImage
        {
            get { return backgroundImage; }
            set 
            { 
                backgroundImage = value;
                ImageStates.Clear();
                ImageStates.Add(backgroundImage);
            }
        }

		/// <summary>
		/// Creates a new Page
		/// </summary>
        public Page()
            : base()
        {            
            BackgroundImage = backgroundImage;
            backgroundImage.TextureName = DefaultBackgroundImage;
            ImageStateIndex = 0;
        }

		/// <summary>
		/// Initializes the Page
		/// </summary>
		/// <param name="contentManager">The ContentManager from which to load Content</param>
		/// <param name="graphicsDevice">The GraphicsDevice to use</param>
        internal override void Initialize(MenuProject parentProject, ContentManager contentManager, GraphicsDevice graphicsDevice)
        {
            base.Initialize(parentProject, contentManager, graphicsDevice);
       
        }

        /// <summary>
        /// Creates a clone of the item
        /// </summary>
        /// <returns>A clone of the item</returns>
        public override MenuItem Clone()
        {
            Page clone = (Page)base.Clone();

            clone.backgroundImage = this.backgroundImage.Clone();
            clone.ImageStates.Add(clone.backgroundImage);

            return clone;
        }

		/// <summary>
		/// Called when the page is added to its parent
		/// </summary>
        protected override void OnAddedToParent()
        {
            base.OnAddedToParent();

            Debug.Assert(Parent is MenuProject);

            // Take dimensions from parent project
            Dimensions = Parent.Dimensions;
        }

    }
}